
import 'package:app/generated/r.dart';
import 'package:app/model/user_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/model/select_model.dart';
import 'package:flutter_jpf_core/widgets/jpfbutton.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_jpf_core/core_enum.dart';
import 'package:flutter_jpf_core/page/base_state_page.dart';
import 'package:flutter_jpf_core/util/colors_util.dart';
import 'package:flutter_jpf_core/util/data_util.dart';
import 'package:flutter_jpf_core/extension/map_extension.dart';
import 'package:flutter_jpf_core/widgets/widget_factory.dart';
import 'package:flutter_jpf_core/widgets/jpftext.dart';

//'/mine':(BuildContext context) => MinePage()
//调用：Navigator.of(context).pushNamed("/mine",arguments: {"title":""});
class MinePage  extends CommBasePage{

  @override
  CommBaseState getPageState() {
    return MinePageState();
  }

}
class MinePageState extends CommBaseState<MinePage> {

  String title = "我的";
  int _currentPage = 1;
  EasyRefreshController _refreshController = EasyRefreshController();
  List<SelectModel> _lstData = new List<SelectModel>();
  Object packageInfo;//PackageInfo

  ///////////////生命周期//////////////////////
  //初始化参数
  @override
  void initBaseParams() {
    // TODO: implement initBaseParams
  }

  //初始化页面数据，父类Widget build(BuildContext context)延时之后
  @override
  void initPageData() {
    Map data = getPageArguments();
    if(!DataUtil.isMapEmpty(data)){
      if(data["title"] != null){
        setState(() {
          title = data.strValue("title");
        });
      }
    }
    queryServiceData();
  }

  ///////////////接口相关//////////////////////
  @override
  void queryServiceData({ServiceType type = ServiceType.Default, bool showAnimail = true}) {
    Future.delayed(Duration(milliseconds: 1000),(){
      //关闭动画
      _refreshController.resetLoadState();
      _refreshController.finishRefresh(success: true);
      _refreshController.finishLoad(
          success: true,
          noMore: false);
      hideProgressDialog();
    });
  }


  ///////////////操作相关//////////////////////
  //提交数据
  void submitAction(){

  }


  ///////////////UI相关//////////////////////
  //页面UI
  @override
  Widget getViewsWidget() {

    Size screenSize = MediaQuery.of(context).size;
    //留海高度
    double topAdd = MediaQuery.of(context).padding.top;
    UserModel user = UserModel.getCurrentUser();
    hideProgressDialog();

      // TODO: implement getViewsWidget
    return Scaffold(
        appBar: WidgetFatory.createMyAppBar(title, context,hasLeftIcon: false),
        backgroundColor: ColorsUtil.view_background,
        /*persistentFooterButtons:  [
          Container(width: ScreenUtil.screenWidth,height: 45,child: Row(children: [Expanded(child: JPFButton("确定",(){
            //showToastTip("建设中，请稍等");
            submitAction();
          }),flex: 1,)],),)],*/
        body: EasyRefresh(
            controller: _refreshController,
            enableControlFinishRefresh: true,
            enableControlFinishLoad: true,
            header: MaterialHeader(),
            footer: MaterialFooter(),

            child: Column(
              children: [
              Container(
                color: Colors.white,padding: EdgeInsets.only(bottom: 10),
              child: Stack(
                children: [
                  Container(
                    height: 326 / 708 * screenSize.width,
                    margin: EdgeInsets.only(left: 10,right: 10,top: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(15.0)),
                      image: DecorationImage(image: AssetImage(R.img_header_bg),fit: BoxFit.cover,),
                    ),
                    child: Row(
                      children: [
                        Container(
                          decoration: new BoxDecoration(
                            //背景
                            color: Colors.white,
                            //设置四周圆角 角度
                            borderRadius: BorderRadius.all(Radius.circular(43.0)),
                            //设置四周边框
                            border: new Border.all(width: 2, color: Colors.white),
                          ),
                          margin: EdgeInsets.only(left: 30),
                          child: ClipOval(
                            child: user.headPictureUrl.length > 0
                                ? Image.network( user.headPictureUrl, height: 86,width: 86, fit: BoxFit.cover,)
                                : Image.asset(R.img_tab_me1,height: 86,width: 86,fit: BoxFit.cover,),
                          ),
                        ),
                        JPFText(user.userName,textSize: 21,alignment: Alignment.center,bold: FontWeight.bold,textColor: Colors.white,margin: EdgeInsets.only(left: 15),),
                      ],
                    ),
                  ),
                ],
              ),
            ),_lstData.length<1?nodataView():ListView.builder(
                  itemCount: _lstData.length,
                  itemBuilder: (BuildContext context, int index) {
                    return listItemView(index);
                  },
                ),
              ]),
            onRefresh: () async {
              queryServiceData(type: ServiceType.Refresh);
            },
            onLoad: () async {
              queryServiceData(type: ServiceType.LoadMore);
            })
    );
  }

  ///////////////get/set//////////////////////
  Widget listItemView(int index){
    var item = _lstData[index];
    return Container(color: ColorsUtil.white,
      child: Container(height: 45,
        margin: EdgeInsets.only(left: 10,right: 10,top: 5,bottom: 5),
        decoration: BoxDecoration(color: ColorsUtil.view_background,borderRadius: BorderRadius.all(Radius.circular(5))),
        child:
        JPFText("${item}",width: 100,margin: EdgeInsets.only(left: 10),),),);
  }

}